#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
const ll N = 2e5 + 20;
ll a[N], pre[N];
void solve()
{
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++)
    {
        cin >> a[i];
        
    }
    ll ans = -1e18;
    for(ll i=1;i<=n;i++)
    {
        if(i==1)
        {
            pre[i] = a[i];
        }
        
        pre[i] = max(a[i], pre[i-1] + a[i]);
        ans = max(pre[i], ans);
    }
    cout << ans << endl;
}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
